package org.edith.shiro.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.edith.shiro.dataobject.SysRoleDO;

import java.util.List;

/**
 *  角色DAO
 *
 */
public interface SysRoleDAO {

    /**
     * 通过用户ID查询角色集合
     *
     * @param userId 用户ID
     * @return List<SysRoleDO> 角色集合
     */
    @Results(value = {
            @Result(column = "role_id",property = "roleId"),
            @Result(column = "role_name",property = "roleName"),
            @Result(column = "remark",property = "remark"),
            @Result(column = "create_time",property = "createTime")
    })
    @Select( "        SELECT sr.* FROM sys_role as sr\n" +
            "        LEFT JOIN sys_user_role as se ON sr.role_id=se.role_id\n" +
            "        WHERE se.user_id = #{userId}" )
    List<SysRoleDO> selectSysRoleByUserId(Long userId);

    @Insert( "        create table  if not exists sys_role\n" +
            "        (\n" +
            "          role_id   bigint auto_increment comment '角色ID' primary key,\n" +
            "          role_name varchar(50) not null comment '角色名称',\n" +
            "          remark    varchar(256) null comment '备注信息',\n" +
            "          create_time  datetime default CURRENT_TIMESTAMP null comment '创建时间'\n" +
            "        ) comment '角色表' charset = utf8;" )
    void createTable();
	
}
